﻿Imports System.Data.OleDb

Public Class addNew
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub btnAddNew_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnAddNew.Click
        Dim myGUID As New System.Guid
        myGUID = Guid.NewGuid()

        Dim newPictureName = myGUID.ToString() + ".jpg"

        If fu_Picture.HasFile Then
            Dim location = Request.MapPath("pictures") & "/" & newPictureName
            fu_Picture.SaveAs(location)
        End If

        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("dbDusanCS").ConnectionString)
        Dim SqlString As String = "Insert into TorontoPictures(PictureOwner,TorontoPictureName,Description,Details, Location, YearTaken,Picture) Values ('guest', @param1,@param2,@param3,@param4,@param5,@param6)"
        Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@param1", tb_PictureName.Text)
        cmd.Parameters.AddWithValue("@param2", tb_Description.Text)
        cmd.Parameters.AddWithValue("@param3", tb_Details.Text)
        cmd.Parameters.AddWithValue("@param4", tb_Location.Text)
        cmd.Parameters.AddWithValue("@param5", tb_YearTaken.Text)
        cmd.Parameters.AddWithValue("@param6", "pictures/" & newPictureName)
        oleDbConn.Open()
        cmd.ExecuteNonQuery()

        Response.Redirect("confirmation.aspx")


    End Sub
End Class